﻿Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports BusinessRule.IBusiness
Imports DatabaseAccess.IDAL
Imports System.Data
Imports BusinessRule.DTO
Imports BusinessRule.Common
Imports DatabaseAccess.DALFactory

Public Class uMESExampleBusiness
    Implements uMESExampleIBusiness
    Private dal As IOracleDAL = uMESDalContext.instance.GetDalObject()

    ''' <summary>
    ''' 获取用户信息
    ''' </summary>
    ''' <returns></returns>
    Private Function GetLoginNameInfo(ByVal paraEntity As uMESPagingDataDTO) As uMESProcessResult Implements uMESExampleIBusiness.GetLoginNameInfo
        Dim dtMain As DataTable = dal.GetLoginNameInfo(paraEntity.QueryCondition)
        Dim oResult As New uMESProcessResult


        Dim strPlanIDs As String = ""

        dtMain.Columns.Add("rowindex", System.Type.GetType("System.Int32"))
        Dim i As Integer = 0
        For Each dr As DataRow In dtMain.Rows
            dr.BeginEdit()
            dr("rowindex") = i + 1
            dr.EndEdit()
            i += 1
        Next
        If paraEntity.CurrentPageIndex = 0 Then

            Return Nothing
        End If
        Dim startIndex As Integer = (paraEntity.CurrentPageIndex - 1) * paraEntity.PageSize + 1
        Dim endIndex As Integer = paraEntity.CurrentPageIndex * paraEntity.PageSize
        Dim RowCount As Integer = dtMain.Rows.Count
        Dim b As Integer = 0
        Dim a As Integer = Math.DivRem(RowCount, paraEntity.PageSize, b)
        Dim PageCount As Integer = 0
        If b > 0 Then
            PageCount = a + 1
        Else
            PageCount = a
        End If
        Dim dtHistory As New DataTable()
        Dim ds As New DataSet()
        Dim drCollection As DataRow() = dtMain.Select("rowindex>=" & startIndex & " and rowindex<=" & endIndex)
        If dtMain.Rows.Count > 0 Then
            dtMain = Common.CurrentInfo.ToDataTable(drCollection)
        End If
        oResult.DBTable = dtMain

        If dtMain IsNot Nothing Then
            oResult.RowCount = RowCount.ToString()
            oResult.PageCount = PageCount.ToString()
        End If
        Return oResult

    End Function

    ''' <summary>
    ''' 获取用户信息
    ''' </summary>
    ''' <returns></returns>
    Private Function UpdateUserFactory(ByVal oExamle As uMESExampleDTO) As uMESProcessResult Implements uMESExampleIBusiness.UpdateUserFactory

        Dim oResult As New uMESProcessResult
        oResult = dal.UpdateUserFactory(oExamle)
        Return oResult

    End Function

    ''' <summary>
    ''' 获取当前时间所在周的第几天
    ''' </summary>
    ''' <returns></returns>
    Private Function GetDaysOfWeek() As Integer
        Dim dayofweek As DayOfWeek = System.DateTime.Now.DayOfWeek
        Dim Day As Integer = 0
        Select Case dayofweek
            Case dayofweek.Monday
                Day = 1
                Exit Select
            Case dayofweek.Tuesday
                Day = 2
                Exit Select
            Case dayofweek.Wednesday
                Day = 3
                Exit Select
            Case dayofweek.Thursday
                Day = 4
                Exit Select
            Case dayofweek.Friday
                Day = 5
                Exit Select
            Case dayofweek.Saturday
                Day = 6
                Exit Select
            Case dayofweek.Sunday
                Day = 7
                Exit Select
            Case Else
                Exit Select
        End Select
        Return Day
    End Function
End Class

